/*
 * Copyright (c) 2019 Author: Fancyears Milos Malvis @1243093366@qq.com
 * ALL COPYRIGHT REVERSED.
 */

package com.fancyears.util;

/**
 * @Author: Fancyears Milos Malvis
 * @Date: Created in  2019/6/19 17:36
 * @Modified By:
 */
import java.util.Random;

/**
 * 字符串助手:
 *
 * 目前没有什么可以拓展的大功能，只是想更加简便的对字符串进行非空判断
 *
 *
 * @author Administrator
 *
 */
public class EncryptCodeUtils {
    final static char[] chr = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
            'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
            'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
            'x', 'y', 'z','.','_','+','='
    };
    private final static Random random = new Random();

    /**
     * 获取随机的字符串长度，字符串仅为ASICII码
     *
     * @param length
     * @return
     */
    public static String getRandomChar(int length) {
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < length; i++) {
            buffer.append(chr[random.nextInt(chr.length)]);
        }
        return buffer.toString();
    }

    /**
     * 对目标字符串进行非空判断，如果是长度为0或为null，则返回false，否则返回true
     *
     * 对于" "之类的空格字符串，一定返回true，如果这种字符串认为是空字符串，则调用此函数前应该先
     *
     * 去空格操作{@see String#trim()}
     *
     * @param str
     *            目标字符串
     * @return
     */
    public static boolean validateString(String str) {
        if (null == str || str.trim().length() <= 0) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        System.out.println(getRandomChar(16));
    }
}